{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "69c9b7cf",
   "metadata": {},
   "source": [
    "------------\n",
    "* 2022/10/9/week 08\n",
    "* Python学习记录\n",
    "* 记录人：wu-huichun\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02419389",
   "metadata": {},
   "source": [
    "# 1.等待用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fe1dd337",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "按下 enter 键后退出。\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"\\n\\n按下 enter 键后退出。\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33760b62",
   "metadata": {},
   "source": [
    "# 2.同一条显示多条语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c7ee6e0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "runoob\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys; x = 'runoob'; sys.stdout.write(x + '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d88214c3",
   "metadata": {},
   "source": [
    "# 3.多个语句构成代码组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b1406cbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "expression = \"happy\"\n",
    "suite = \"ye\"\n",
    "\n",
    "if expression :\n",
    "    suite\n",
    "elif expression : \n",
    "    suite\n",
    "else : \n",
    "    suite"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e856fcf9",
   "metadata": {},
   "source": [
    "# 4.print输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0064033",
   "metadata": {},
   "source": [
    "> * print 默认输出是换行的，如果要实现不换行需要在变量末尾加上 end=\"\"："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "df6db0e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "b\n",
      "----\n",
      "ab\n"
     ]
    }
   ],
   "source": [
    "x = \"a\"\n",
    "y = \"b\"\n",
    "\n",
    "# 换行输出\n",
    "print(x)\n",
    "print(y)\n",
    "print(\"----\")\n",
    "\n",
    "# 不换行输出\n",
    "print(x, end = \"\")\n",
    "print(y, end = \"\")\n",
    "print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12f6afe5",
   "metadata": {},
   "source": [
    "> * end=\"\" 可以设置一些特色符号或字符串："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c1a61176",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456789\n",
      "admin@runoob.com\n",
      "GoogleRunoobTaobao\n"
     ]
    }
   ],
   "source": [
    "print('12345', end = \"\") # 设置空格\n",
    "print('6789')\n",
    "\n",
    "print('admin', end = \"@\") # 设置符号\n",
    "print('runoob.com')\n",
    "\n",
    "print('Google', end = \"Runoob\") # 设置字符串\n",
    "print('Taobao')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "506d960a",
   "metadata": {},
   "source": [
    "# 5.import 与 from...import"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bae9a95",
   "metadata": {},
   "source": [
    "> 1.在python中用 import 或者 from...import 来导入相应的模块。\n",
    "\n",
    "> 2.将整个模块(somemodule)导入，格式为： import somemodule\n",
    "\n",
    "> 3.从某个模块中导入某个函数,格式为： from somemodule import somefunction\n",
    "\n",
    "> 4.从某个模块中导入多个函数,格式为： from somemodule import firstfunc, secondfunc, thirdfunc\n",
    "\n",
    "> 5.将某个模块中的全部函数导入，格式为： from somemodule import *"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2f00ced",
   "metadata": {},
   "source": [
    "### （1）导入 sys 模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3b59fd5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================Python import mode==========================\n",
      "命令行参数为:\n",
      "D:\\Python\\lib\\site-packages\\ipykernel_launcher.py\n",
      "-f\n",
      "C:\\Users\\86134\\AppData\\Roaming\\jupyter\\runtime\\kernel-cd8e8d50-8f53-43e9-991f-4a6a615e5aab.json\n",
      "\n",
      " python 路径为 ['D:\\\\Python\\\\Python\\\\2022-2023-01\\\\Python 自学内容', 'D:\\\\Python\\\\python39.zip', 'D:\\\\Python\\\\DLLs', 'D:\\\\Python\\\\lib', 'D:\\\\Python', '', 'D:\\\\Python\\\\lib\\\\site-packages', 'D:\\\\Python\\\\lib\\\\site-packages\\\\win32', 'D:\\\\Python\\\\lib\\\\site-packages\\\\win32\\\\lib', 'D:\\\\Python\\\\lib\\\\site-packages\\\\Pythonwin']\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print('================Python import mode==========================')\n",
    "print ('命令行参数为:')\n",
    "for i in sys.argv:\n",
    "    print (i)\n",
    "print ('\\n python 路径为',sys.path)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fabae3b",
   "metadata": {},
   "source": [
    "### (2)导入 sys 模块的 argv,path 成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f7b99a43",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================python from import===================================\n",
      "path: ['D:\\\\Python\\\\Python\\\\2022-2023-01\\\\Python 自学内容', 'D:\\\\Python\\\\python39.zip', 'D:\\\\Python\\\\DLLs', 'D:\\\\Python\\\\lib', 'D:\\\\Python', '', 'D:\\\\Python\\\\lib\\\\site-packages', 'D:\\\\Python\\\\lib\\\\site-packages\\\\win32', 'D:\\\\Python\\\\lib\\\\site-packages\\\\win32\\\\lib', 'D:\\\\Python\\\\lib\\\\site-packages\\\\Pythonwin']\n"
     ]
    }
   ],
   "source": [
    "from sys import argv,path  #  导入特定的成员\n",
    " \n",
    "print('================python from import===================================')\n",
    "print('path:',path) # 因为已经导入path成员，所以此处引用时不需要加sys.path"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87687c8f",
   "metadata": {},
   "source": [
    "# 5.命令行参数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b94d178",
   "metadata": {},
   "source": [
    "> 用 sys 的 sys.argv 来获取命令行参数：\n",
    "\n",
    "  * sys.argv 是命令行参数列表\n",
    "\n",
    "  * len(sys.argv) 计算命令行参数个数\n",
    "\n",
    "  * sys.argv [0] 表示脚本名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "41eafac9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "参数个数为： 3 个参数\n",
      "参数列表: ['D:\\\\Python\\\\lib\\\\site-packages\\\\ipykernel_launcher.py', '-f', 'C:\\\\Users\\\\86134\\\\AppData\\\\Roaming\\\\jupyter\\\\runtime\\\\kernel-cd8e8d50-8f53-43e9-991f-4a6a615e5aab.json']\n",
      "脚本名: D:\\Python\\lib\\site-packages\\ipykernel_launcher.py\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print('参数个数为：', len(sys.argv), '个参数')\n",
    "print('参数列表:', str(sys.argv))\n",
    "print('脚本名:', str(sys.argv[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff1c7e9f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
